home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / ITAGS.ICN < prev    next >
Text File  |  1992-11-26  |  4KB  |  125 lines

  1. ############################################################################
  2. #
  3. #    File:     itags.icn
  4. #
  5. #    Subject:  Program to create tags file for Icon programs
  6. #
  7. #    Author:   Robert J. Alexander
  8. #
  9. #    Date:     September 7, 1990
  10. #
  11. ###########################################################################
  12. #
  13. #  Program to create a tags file for an Icon program.  It has the
  14. #  options described in the Sun 3.5 man entry for ctags (except -u --
  15. #  update tags file):
  16. #
  17. #  Usage: itags [-aBFtvwx] [-f tagsfile] file...
  18. #
  19. #    -a   append output to an existing tags file.
  20. #
  21. #    -B   use backward searching patterns (?...?).
  22. #
  23. #    -F   use forward searching patterns (/.../) (default).
  24. #
  25. #    -x   produce a list of object names,  the  line  number  and
  26. #         file name on which each is defined, as well as the text
  27. #         of that line and prints this on  the  standard  output.
  28. #         This  is  a simple index which can be printed out as an
  29. #         off-line readable function index.
  30. #
  31. #    -t   create tags for records. 
  32. #
  33. #    -v   produce on the standard output an  index  of  the  form
  34. #         expected  by  vgrind(1).   This  listing  contains  the
  35. #         function name, file name, and page number (assuming  64
  36. #         line pages).  Since the output will be sorted into lex-
  37. #         icographic order, it may be desired to run  the  output
  38. #         through sort -f.  Sample use:
  39. #              itags -v files | sort -f > index
  40. #              vgrind -x index
  41. #
  42. #    -w   suppress warning diagnostics.
  43. #
  44. ############################################################################
  45. #
  46. #  Links:  isort, filename, options
  47. #
  48. ############################################################################
  49.  
  50. link isort, filename, options
  51.  
  52. global patChar
  53.  
  54. record Tag(fn,line,linenbr,shortline)
  55.  
  56. procedure main(arg)
  57.    local Write,f,fn,idChar,line,linenbr,noWarnings,opt,space,tag,tags,
  58.        tf,tfn,typedef,x
  59.    #
  60.    #  Handle command line options and initialization.
  61.    #
  62.    opt := options(arg,"aBFxtvwuf:")
  63.    if *arg = 0 then
  64.      stop("usage: itags [-aBFtvwx] [-f tagsfile] file...")
  65.    if \opt["u"] then stop("update option (-u) not supported -- rebuild file")
  66.    patChar := if \opt["B"] & /opt["F"] then "?" else "/"
  67.    Write := (if \opt["v"] then VGrind
  68.       else if \opt["x"] then Index
  69.       else {
  70.      tfn := \opt["f"] | "tags"
  71.      tf := open(tfn,if \opt["a"] then "a" else "w") |
  72.            stop("Can't open tags file \"",tfn,"\"")
  73.      Tags
  74.      })
  75.    typedef := opt["t"]
  76.    noWarnings := opt["w"]
  77.    idChar := &letters ++ &digits ++ "_"
  78.    space := ' \t\v\f\r'
  79.    tags := table()
  80.    #
  81.    #  Loop to read files.
  82.    #
  83.    every fn := !arg do {
  84.       if not find(".",fn) then fn ||:= ".icn"
  85.       f := open(fn) | write(&errout,"Couldn't open \"",fn,"\"")
  86.       linenbr := 0
  87.       while line := read(f) do line ? {
  88.      linenbr +:= 1
  89.      if (tab(many(space)) | &null) & =("procedure" | (\typedef,"record")) &
  90.            tab(many(space)) then {
  91.         tag := tab(many(idChar))
  92.         if x := \tags[tag] then {
  93.            if /noWarnings then
  94.              write(&errout,"Duplicate entry in file ",fn,", line ",linenbr,
  95.              ": ",tag,"\nSecond entry ignored")
  96.            }
  97.         else
  98.           tags[tag] := Tag(fn,line,linenbr,line[1:&pos + 1])
  99.         }
  100.      }
  101.       close(f)
  102.       }
  103.    #
  104.    #  Do requested output.
  105.    #
  106.    every Write(!sort(tags),tf)
  107. end
  108.  
  109.  
  110. #
  111. #  Output procedures.
  112. #
  113. procedure Tags(x,f)
  114.    return write(f,x[1],"\t",x[2].fn,"\t",patChar,"^",x[2].shortline,patChar)
  115. end
  116.  
  117. procedure Index(x)
  118.    return write(left(x[1],*x[1] < 16) | x[1],right(x[2].linenbr,4)," ",
  119.      left(x[2].fn,17),x[2].line)
  120. end
  121.  
  122. procedure VGrind(x)
  123.    return write(x[1]," ",x[2].fn," ",(x[2].linenbr - 1) / 64 + 1)
  124. end
  125.